<template>
	<div>
	    <div class="crumbs">
	        <el-breadcrumb separator="/">
	            <el-breadcrumb-item><i class="el-icon-lx-calendar"></i> 作者管理</el-breadcrumb-item>
	            <el-breadcrumb-item>查看申请签约的作者</el-breadcrumb-item>
	        </el-breadcrumb>
	    </div>
	    <div class="container">
			<template>
				<!--  模糊搜索框,根据笔名来搜素  -->
			  <el-table
			    :data="Authors.filter(data => !search || data.penName.toLowerCase().includes(search.toLowerCase()))"
			    style="width: 100%">
			    <el-table-column
			      label="作者id"
			      prop="authorId">
			    </el-table-column>
			    <el-table-column
			      label="作者笔名"
			      prop="penName">
			    </el-table-column>
				<el-table-column
				  label="作品总数"
				  prop="countbook">
				</el-table-column>
				<el-table-column
				  label="作品总点击量"
				  prop="clicknum">
				</el-table-column>
				<el-table-column
				  label="累计字数"
				  prop="sumbooknum">
				</el-table-column>
				<el-table-column
				  label="电话"
				  prop="authorTel">
				</el-table-column>
				<el-table-column
				  label="QQ"
				  prop="qq">
				</el-table-column>
				<el-table-column
				  label="申请签约时间"
				  prop="authorTime">
				</el-table-column>
			    <el-table-column
			      align="right">
			      <template slot="header" slot-scope="scope">
			        <el-input
			          v-model="search"
			          size="mini"
			          placeholder="输入关键字搜索"/>
			      </template>
			      <template slot-scope="scope">
			        <el-button
			          size="mini"
					  type="success"
			          @click="handleEdit(scope.$index, scope.row)">同意签约申请</el-button>
			        <el-button
			          size="mini"
			          type="danger"
			          @click="handleDelete(scope.$index, scope.row)">驳回</el-button>
			      </template>
			    </el-table-column>
			  </el-table>
			</template>
		</div>
	</div>
</template>

<script>
  import $ from 'jquery'
  export default {
    data() {
      return {
        tableData: [],
        search: '',
		Authors:[],
		Temp:[],
      }
    },
    methods: {
      handleEdit(index, row) {
		// console.log(sessionStorage.getItem("editor"));
		var _this = this;
		_this.Temp = row;
		// console.log(_this.Temp);
		$.ajax({
			url: "http://localhost/editor/agree",
			type: "post",
			// contentType: "application/json;charset=utf-8",
			data:{"authorid":_this.Temp.authorId,"editortel":sessionStorage.getItem("editor")},
			success: function(data) {
				if(data.data[0].countbook==0){
					return;
				}
				location.reload();
			}
		});
		
      },
      handleDelete(index, row) {
		var _this = this;
		_this.Temp = row;
		$.ajax({
			url: "http://localhost/editor/reject",
			type: "post",
			// contentType: "application/json;charset=utf-8",
			data:{"authorid":_this.Temp.authorId},
			success: function(data) {
				console.log(data);
				if(data.data[0].countbook==0){
					return;
				}
				location.reload();
			}
		});
      },
	  select:function(editorTel){
		  var _this = this;
		  console.log(editorTel);
		  $.ajax({
		  	url: "http://localhost/editor/selectSign",
		  	type: "get",
		  	// contentType: "application/json;charset=utf-8",
		  	success: function(data) {
		  		console.log(data);
				if(data.message=="404"){
					return;
				}
		  		_this.Authors = data.data;
				
		  	}
		  });
	  }
    },
	created(){
		if (sessionStorage.getItem("editor")!= null) {	
			var editorTel = sessionStorage.getItem("editor");
			this.select(editorTel);
		}
	}
  }
</script>

<style>
</style>
